
<!DOCTYPE html>

<html>
  
<!-- Mirrored from docs.sympy.org/latest/modules/logic.html by HTTrack Website Copier/3.x [XR&CO'2014], Sat, 15 Jan 2022 03:24:30 GMT -->
<!-- Added by HTTrack --><meta http-equiv="content-type" content="text/html;charset=utf-8" /><!-- /Added by HTTrack -->
<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="generator" content="Docutils 0.17.1: http://docutils.sourceforge.net/" />

    <title>Logic &#8212; SymPy 1.9 documentation</title>
    <link rel="stylesheet" type="text/css" href="../_static/pygments.css" />
    <link rel="stylesheet" type="text/css" href="../_static/default.css" />
    <link rel="stylesheet" type="text/css" href="../_static/graphviz.css" />
    <link rel="stylesheet" type="text/css" href="../_static/plot_directive.css" />
    <link rel="stylesheet" type="text/css" href="../../../live.sympy.org/static/live-core.css" />
    <link rel="stylesheet" type="text/css" href="../../../live.sympy.org/static/live-autocomplete.css" />
    <link rel="stylesheet" type="text/css" href="../../../live.sympy.org/static/live-sphinx.css" />
    
    <script data-url_root="../" id="documentation_options" src="../_static/documentation_options.js"></script>
    <script src="../_static/jquery.js"></script>
    <script src="../_static/underscore.js"></script>
    <script src="../_static/doctools.js"></script>
    <script src="../../../live.sympy.org/static/utilities.js"></script>
    <script src="../../../live.sympy.org/static/external/classy.js"></script>
    <script src="../../../live.sympy.org/static/live-core.js"></script>
    <script src="../../../live.sympy.org/static/live-autocomplete.js"></script>
    <script src="../../../live.sympy.org/static/live-sphinx.js"></script>
    <script async="async" src="../../../cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/latest8331.js?config=TeX-AMS_HTML-full"></script>
    <script type="text/x-mathjax-config">MathJax.Hub.Config({"tex2jax": {"inlineMath": [["\\(", "\\)"]], "displayMath": [["\\[", "\\]"]]}})</script>
    
    <link rel="shortcut icon" href="../_static/sympy-notailtext-favicon.ico"/>
    <link href="logic.html" rel="canonical" />
    
    <link rel="index" title="Index" href="../genindex.html" />
    <link rel="search" title="Search" href="../search.html" />
    <link rel="next" title="Matrices" href="matrices/index.html" />
    <link rel="prev" title="Lie Algebra" href="liealgebras/index.html" /> 
  </head><body>
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../genindex.html" title="General Index"
             accesskey="I">index</a></li>
        <li class="right" >
          <a href="../py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="right" >
          <a href="matrices/index.html" title="Matrices"
             accesskey="N">next</a> |</li>
        <li class="right" >
          <a href="liealgebras/index.html" title="Lie Algebra"
             accesskey="P">previous</a> |</li>
        <li class="nav-item nav-item-0"><a href="../index.html">SymPy 1.9 documentation</a> &#187;</li>
          <li class="nav-item nav-item-1"><a href="index.html" accesskey="U">SymPy Modules Reference</a> &#187;</li>
        <li class="nav-item nav-item-this"><a href="#">Logic</a></li> 
      </ul>
    </div>  

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body" role="main">
            
  <section id="module-sympy.logic">
<span id="logic"></span><h1>Logic<a class="headerlink" href="#module-sympy.logic" title="Permalink to this headline">¶</a></h1>
<section id="introduction">
<h2>Introduction<a class="headerlink" href="#introduction" title="Permalink to this headline">¶</a></h2>
<p>The logic module for SymPy allows to form and manipulate logic expressions
using symbolic and Boolean values.</p>
</section>
<section id="forming-logical-expressions">
<h2>Forming logical expressions<a class="headerlink" href="#forming-logical-expressions" title="Permalink to this headline">¶</a></h2>
<p>You can build Boolean expressions with the standard python operators <code class="docutils literal notranslate"><span class="pre">&amp;</span></code>
(<a class="reference internal" href="#sympy.logic.boolalg.And" title="sympy.logic.boolalg.And"><code class="xref py py-class docutils literal notranslate"><span class="pre">And</span></code></a>), <code class="docutils literal notranslate"><span class="pre">|</span></code> (<a class="reference internal" href="#sympy.logic.boolalg.Or" title="sympy.logic.boolalg.Or"><code class="xref py py-class docutils literal notranslate"><span class="pre">Or</span></code></a>), <code class="docutils literal notranslate"><span class="pre">~</span></code> (<a class="reference internal" href="#sympy.logic.boolalg.Not" title="sympy.logic.boolalg.Not"><code class="xref py py-class docutils literal notranslate"><span class="pre">Not</span></code></a>):</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="o">*</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">x</span><span class="p">,</span> <span class="n">y</span> <span class="o">=</span> <span class="n">symbols</span><span class="p">(</span><span class="s1">&#39;x,y&#39;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">y</span> <span class="o">|</span> <span class="p">(</span><span class="n">x</span> <span class="o">&amp;</span> <span class="n">y</span><span class="p">)</span>
<span class="go">y | (x &amp; y)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">x</span> <span class="o">|</span> <span class="n">y</span>
<span class="go">x | y</span>
<span class="gp">&gt;&gt;&gt; </span><span class="o">~</span><span class="n">x</span>
<span class="go">~x</span>
</pre></div>
</div>
<p>You can also form implications with <code class="docutils literal notranslate"><span class="pre">&gt;&gt;</span></code> and <code class="docutils literal notranslate"><span class="pre">&lt;&lt;</span></code>:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">x</span> <span class="o">&gt;&gt;</span> <span class="n">y</span>
<span class="go">Implies(x, y)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">x</span> <span class="o">&lt;&lt;</span> <span class="n">y</span>
<span class="go">Implies(y, x)</span>
</pre></div>
</div>
<p>Like most types in SymPy, Boolean expressions inherit from <a class="reference internal" href="core.html#sympy.core.basic.Basic" title="sympy.core.basic.Basic"><code class="xref py py-class docutils literal notranslate"><span class="pre">Basic</span></code></a>:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="p">(</span><span class="n">y</span> <span class="o">&amp;</span> <span class="n">x</span><span class="p">)</span><span class="o">.</span><span class="n">subs</span><span class="p">({</span><span class="n">x</span><span class="p">:</span> <span class="kc">True</span><span class="p">,</span> <span class="n">y</span><span class="p">:</span> <span class="kc">True</span><span class="p">})</span>
<span class="go">True</span>
<span class="gp">&gt;&gt;&gt; </span><span class="p">(</span><span class="n">x</span> <span class="o">|</span> <span class="n">y</span><span class="p">)</span><span class="o">.</span><span class="n">atoms</span><span class="p">()</span>
<span class="go">{x, y}</span>
</pre></div>
</div>
<p>The logic module also includes the following functions to derive boolean expressions
from their truth tables-</p>
<dl class="py function">
<dt class="sig sig-object py" id="sympy.logic.boolalg.SOPform">
<span class="sig-prename descclassname"><span class="pre">sympy.logic.boolalg.</span></span><span class="sig-name descname"><span class="pre">SOPform</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">variables</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">minterms</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">dontcares</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/logic/boolalg.py#L2437-L2505"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.logic.boolalg.SOPform" title="Permalink to this definition">¶</a></dt>
<dd><p>The SOPform function uses simplified_pairs and a redundant group-
eliminating algorithm to convert the list of all input combos that
generate ‘1’ (the minterms) into the smallest Sum of Products form.</p>
<p>The variables must be given as the first argument.</p>
<p>Return a logical Or function (i.e., the “sum of products” or “SOP”
form) that gives the desired outcome. If there are inputs that can
be ignored, pass them as a list, too.</p>
<p>The result will be one of the (perhaps many) functions that satisfy
the conditions.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.logic</span> <span class="kn">import</span> <span class="n">SOPform</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">symbols</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">w</span><span class="p">,</span> <span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">,</span> <span class="n">z</span> <span class="o">=</span> <span class="n">symbols</span><span class="p">(</span><span class="s1">&#39;w x y z&#39;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">minterms</span> <span class="o">=</span> <span class="p">[[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">],</span> <span class="p">[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">],</span>
<span class="gp">... </span>            <span class="p">[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">],</span> <span class="p">[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">],</span> <span class="p">[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">]]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">dontcares</span> <span class="o">=</span> <span class="p">[[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">],</span> <span class="p">[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">0</span><span class="p">],</span> <span class="p">[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">]]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">SOPform</span><span class="p">([</span><span class="n">w</span><span class="p">,</span> <span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">,</span> <span class="n">z</span><span class="p">],</span> <span class="n">minterms</span><span class="p">,</span> <span class="n">dontcares</span><span class="p">)</span>
<span class="go">(y &amp; z) | (~w &amp; ~x)</span>
</pre></div>
</div>
<p>The terms can also be represented as integers:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">minterms</span> <span class="o">=</span> <span class="p">[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">7</span><span class="p">,</span> <span class="mi">11</span><span class="p">,</span> <span class="mi">15</span><span class="p">]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">dontcares</span> <span class="o">=</span> <span class="p">[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">5</span><span class="p">]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">SOPform</span><span class="p">([</span><span class="n">w</span><span class="p">,</span> <span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">,</span> <span class="n">z</span><span class="p">],</span> <span class="n">minterms</span><span class="p">,</span> <span class="n">dontcares</span><span class="p">)</span>
<span class="go">(y &amp; z) | (~w &amp; ~x)</span>
</pre></div>
</div>
<p>They can also be specified using dicts, which does not have to be fully
specified:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">minterms</span> <span class="o">=</span> <span class="p">[{</span><span class="n">w</span><span class="p">:</span> <span class="mi">0</span><span class="p">,</span> <span class="n">x</span><span class="p">:</span> <span class="mi">1</span><span class="p">},</span> <span class="p">{</span><span class="n">y</span><span class="p">:</span> <span class="mi">1</span><span class="p">,</span> <span class="n">z</span><span class="p">:</span> <span class="mi">1</span><span class="p">,</span> <span class="n">x</span><span class="p">:</span> <span class="mi">0</span><span class="p">}]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">SOPform</span><span class="p">([</span><span class="n">w</span><span class="p">,</span> <span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">,</span> <span class="n">z</span><span class="p">],</span> <span class="n">minterms</span><span class="p">)</span>
<span class="go">(x &amp; ~w) | (y &amp; z &amp; ~x)</span>
</pre></div>
</div>
<p>Or a combination:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">minterms</span> <span class="o">=</span> <span class="p">[</span><span class="mi">4</span><span class="p">,</span> <span class="mi">7</span><span class="p">,</span> <span class="mi">11</span><span class="p">,</span> <span class="p">[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">]]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">dontcares</span> <span class="o">=</span> <span class="p">[{</span><span class="n">w</span> <span class="p">:</span> <span class="mi">0</span><span class="p">,</span> <span class="n">x</span> <span class="p">:</span> <span class="mi">0</span><span class="p">,</span> <span class="n">y</span><span class="p">:</span> <span class="mi">0</span><span class="p">},</span> <span class="mi">5</span><span class="p">]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">SOPform</span><span class="p">([</span><span class="n">w</span><span class="p">,</span> <span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">,</span> <span class="n">z</span><span class="p">],</span> <span class="n">minterms</span><span class="p">,</span> <span class="n">dontcares</span><span class="p">)</span>
<span class="go">(w &amp; y &amp; z) | (~w &amp; ~y) | (x &amp; z &amp; ~w)</span>
</pre></div>
</div>
<p class="rubric">References</p>
<dl class="citation">
<dt class="label" id="r519"><span class="brackets"><a class="fn-backref" href="#id1">R519</a></span></dt>
<dd><p><a class="reference external" href="https://en.wikipedia.org/wiki/Quine-McCluskey_algorithm">https://en.wikipedia.org/wiki/Quine-McCluskey_algorithm</a></p>
</dd>
</dl>
</dd></dl>

<dl class="py function">
<dt class="sig sig-object py" id="sympy.logic.boolalg.POSform">
<span class="sig-prename descclassname"><span class="pre">sympy.logic.boolalg.</span></span><span class="sig-name descname"><span class="pre">POSform</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">variables</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">minterms</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">dontcares</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/logic/boolalg.py#L2508-L2581"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.logic.boolalg.POSform" title="Permalink to this definition">¶</a></dt>
<dd><p>The POSform function uses simplified_pairs and a redundant-group
eliminating algorithm to convert the list of all input combinations
that generate ‘1’ (the minterms) into the smallest Product of Sums form.</p>
<p>The variables must be given as the first argument.</p>
<p>Return a logical And function (i.e., the “product of sums” or “POS”
form) that gives the desired outcome. If there are inputs that can
be ignored, pass them as a list, too.</p>
<p>The result will be one of the (perhaps many) functions that satisfy
the conditions.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.logic</span> <span class="kn">import</span> <span class="n">POSform</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">symbols</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">w</span><span class="p">,</span> <span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">,</span> <span class="n">z</span> <span class="o">=</span> <span class="n">symbols</span><span class="p">(</span><span class="s1">&#39;w x y z&#39;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">minterms</span> <span class="o">=</span> <span class="p">[[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">],</span> <span class="p">[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">],</span> <span class="p">[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">],</span>
<span class="gp">... </span>            <span class="p">[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">],</span> <span class="p">[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">]]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">dontcares</span> <span class="o">=</span> <span class="p">[[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">],</span> <span class="p">[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">0</span><span class="p">],</span> <span class="p">[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">]]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">POSform</span><span class="p">([</span><span class="n">w</span><span class="p">,</span> <span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">,</span> <span class="n">z</span><span class="p">],</span> <span class="n">minterms</span><span class="p">,</span> <span class="n">dontcares</span><span class="p">)</span>
<span class="go">z &amp; (y | ~w)</span>
</pre></div>
</div>
<p>The terms can also be represented as integers:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">minterms</span> <span class="o">=</span> <span class="p">[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">7</span><span class="p">,</span> <span class="mi">11</span><span class="p">,</span> <span class="mi">15</span><span class="p">]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">dontcares</span> <span class="o">=</span> <span class="p">[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">5</span><span class="p">]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">POSform</span><span class="p">([</span><span class="n">w</span><span class="p">,</span> <span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">,</span> <span class="n">z</span><span class="p">],</span> <span class="n">minterms</span><span class="p">,</span> <span class="n">dontcares</span><span class="p">)</span>
<span class="go">z &amp; (y | ~w)</span>
</pre></div>
</div>
<p>They can also be specified using dicts, which does not have to be fully
specified:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">minterms</span> <span class="o">=</span> <span class="p">[{</span><span class="n">w</span><span class="p">:</span> <span class="mi">0</span><span class="p">,</span> <span class="n">x</span><span class="p">:</span> <span class="mi">1</span><span class="p">},</span> <span class="p">{</span><span class="n">y</span><span class="p">:</span> <span class="mi">1</span><span class="p">,</span> <span class="n">z</span><span class="p">:</span> <span class="mi">1</span><span class="p">,</span> <span class="n">x</span><span class="p">:</span> <span class="mi">0</span><span class="p">}]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">POSform</span><span class="p">([</span><span class="n">w</span><span class="p">,</span> <span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">,</span> <span class="n">z</span><span class="p">],</span> <span class="n">minterms</span><span class="p">)</span>
<span class="go">(x | y) &amp; (x | z) &amp; (~w | ~x)</span>
</pre></div>
</div>
<p>Or a combination:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">minterms</span> <span class="o">=</span> <span class="p">[</span><span class="mi">4</span><span class="p">,</span> <span class="mi">7</span><span class="p">,</span> <span class="mi">11</span><span class="p">,</span> <span class="p">[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">]]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">dontcares</span> <span class="o">=</span> <span class="p">[{</span><span class="n">w</span> <span class="p">:</span> <span class="mi">0</span><span class="p">,</span> <span class="n">x</span> <span class="p">:</span> <span class="mi">0</span><span class="p">,</span> <span class="n">y</span><span class="p">:</span> <span class="mi">0</span><span class="p">},</span> <span class="mi">5</span><span class="p">]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">POSform</span><span class="p">([</span><span class="n">w</span><span class="p">,</span> <span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">,</span> <span class="n">z</span><span class="p">],</span> <span class="n">minterms</span><span class="p">,</span> <span class="n">dontcares</span><span class="p">)</span>
<span class="go">(w | x) &amp; (y | ~w) &amp; (z | ~y)</span>
</pre></div>
</div>
<p class="rubric">References</p>
<dl class="citation">
<dt class="label" id="r520"><span class="brackets"><a class="fn-backref" href="#id2">R520</a></span></dt>
<dd><p><a class="reference external" href="https://en.wikipedia.org/wiki/Quine-McCluskey_algorithm">https://en.wikipedia.org/wiki/Quine-McCluskey_algorithm</a></p>
</dd>
</dl>
</dd></dl>

</section>
<section id="boolean-functions">
<h2>Boolean functions<a class="headerlink" href="#boolean-functions" title="Permalink to this headline">¶</a></h2>
<dl class="py class">
<dt class="sig sig-object py" id="sympy.logic.boolalg.Boolean">
<em class="property"><span class="pre">class</span> </em><span class="sig-prename descclassname"><span class="pre">sympy.logic.boolalg.</span></span><span class="sig-name descname"><span class="pre">Boolean</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="o"><span class="pre">*</span></span><span class="n"><span class="pre">args</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/logic/boolalg.py#L63-L189"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.logic.boolalg.Boolean" title="Permalink to this definition">¶</a></dt>
<dd><p>A boolean object is an object for which logic operations make sense.</p>
<dl class="py method">
<dt class="sig sig-object py" id="sympy.logic.boolalg.Boolean.as_set">
<span class="sig-name descname"><span class="pre">as_set</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/logic/boolalg.py#L134-L173"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.logic.boolalg.Boolean.as_set" title="Permalink to this definition">¶</a></dt>
<dd><p>Rewrites Boolean expression in terms of real sets.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">Symbol</span><span class="p">,</span> <span class="n">Eq</span><span class="p">,</span> <span class="n">Or</span><span class="p">,</span> <span class="n">And</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">x</span> <span class="o">=</span> <span class="n">Symbol</span><span class="p">(</span><span class="s1">&#39;x&#39;</span><span class="p">,</span> <span class="n">real</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Eq</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="mi">0</span><span class="p">)</span><span class="o">.</span><span class="n">as_set</span><span class="p">()</span>
<span class="go">{0}</span>
<span class="gp">&gt;&gt;&gt; </span><span class="p">(</span><span class="n">x</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">)</span><span class="o">.</span><span class="n">as_set</span><span class="p">()</span>
<span class="go">Interval.open(0, oo)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">And</span><span class="p">(</span><span class="o">-</span><span class="mi">2</span> <span class="o">&lt;</span> <span class="n">x</span><span class="p">,</span> <span class="n">x</span> <span class="o">&lt;</span> <span class="mi">2</span><span class="p">)</span><span class="o">.</span><span class="n">as_set</span><span class="p">()</span>
<span class="go">Interval.open(-2, 2)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Or</span><span class="p">(</span><span class="n">x</span> <span class="o">&lt;</span> <span class="o">-</span><span class="mi">2</span><span class="p">,</span> <span class="mi">2</span> <span class="o">&lt;</span> <span class="n">x</span><span class="p">)</span><span class="o">.</span><span class="n">as_set</span><span class="p">()</span>
<span class="go">Union(Interval.open(-oo, -2), Interval.open(2, oo))</span>
</pre></div>
</div>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.logic.boolalg.Boolean.equals">
<span class="sig-name descname"><span class="pre">equals</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">other</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/logic/boolalg.py#L104-L128"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.logic.boolalg.Boolean.equals" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns True if the given formulas have the same truth table.
For two formulas to be equal they must have the same literals.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.abc</span> <span class="kn">import</span> <span class="n">A</span><span class="p">,</span> <span class="n">B</span><span class="p">,</span> <span class="n">C</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.logic.boolalg</span> <span class="kn">import</span> <span class="n">And</span><span class="p">,</span> <span class="n">Or</span><span class="p">,</span> <span class="n">Not</span>
<span class="gp">&gt;&gt;&gt; </span><span class="p">(</span><span class="n">A</span> <span class="o">&gt;&gt;</span> <span class="n">B</span><span class="p">)</span><span class="o">.</span><span class="n">equals</span><span class="p">(</span><span class="o">~</span><span class="n">B</span> <span class="o">&gt;&gt;</span> <span class="o">~</span><span class="n">A</span><span class="p">)</span>
<span class="go">True</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Not</span><span class="p">(</span><span class="n">And</span><span class="p">(</span><span class="n">A</span><span class="p">,</span> <span class="n">B</span><span class="p">,</span> <span class="n">C</span><span class="p">))</span><span class="o">.</span><span class="n">equals</span><span class="p">(</span><span class="n">And</span><span class="p">(</span><span class="n">Not</span><span class="p">(</span><span class="n">A</span><span class="p">),</span> <span class="n">Not</span><span class="p">(</span><span class="n">B</span><span class="p">),</span> <span class="n">Not</span><span class="p">(</span><span class="n">C</span><span class="p">)))</span>
<span class="go">False</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Not</span><span class="p">(</span><span class="n">And</span><span class="p">(</span><span class="n">A</span><span class="p">,</span> <span class="n">Not</span><span class="p">(</span><span class="n">A</span><span class="p">)))</span><span class="o">.</span><span class="n">equals</span><span class="p">(</span><span class="n">Or</span><span class="p">(</span><span class="n">B</span><span class="p">,</span> <span class="n">Not</span><span class="p">(</span><span class="n">B</span><span class="p">)))</span>
<span class="go">False</span>
</pre></div>
</div>
</dd></dl>

</dd></dl>

<dl class="py class">
<dt class="sig sig-object py" id="sympy.logic.boolalg.BooleanTrue">
<em class="property"><span class="pre">class</span> </em><span class="sig-prename descclassname"><span class="pre">sympy.logic.boolalg.</span></span><span class="sig-name descname"><span class="pre">BooleanTrue</span></span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/logic/boolalg.py#L241-L355"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.logic.boolalg.BooleanTrue" title="Permalink to this definition">¶</a></dt>
<dd><p>SymPy version of True, a singleton that can be accessed via S.true.</p>
<p>This is the SymPy version of True, for use in the logic module. The
primary advantage of using true instead of True is that shorthand boolean
operations like ~ and &gt;&gt; will work as expected on this class, whereas with
True they act bitwise on 1. Functions in the logic module will return this
class when they evaluate to true.</p>
<p class="rubric">Notes</p>
<p>There is liable to be some confusion as to when <code class="docutils literal notranslate"><span class="pre">True</span></code> should
be used and when <code class="docutils literal notranslate"><span class="pre">S.true</span></code> should be used in various contexts
throughout SymPy. An important thing to remember is that
<code class="docutils literal notranslate"><span class="pre">sympify(True)</span></code> returns <code class="docutils literal notranslate"><span class="pre">S.true</span></code>. This means that for the most
part, you can just use <code class="docutils literal notranslate"><span class="pre">True</span></code> and it will automatically be converted
to <code class="docutils literal notranslate"><span class="pre">S.true</span></code> when necessary, similar to how you can generally use 1
instead of <code class="docutils literal notranslate"><span class="pre">S.One</span></code>.</p>
<p>The rule of thumb is:</p>
<p>“If the boolean in question can be replaced by an arbitrary symbolic
<code class="docutils literal notranslate"><span class="pre">Boolean</span></code>, like <code class="docutils literal notranslate"><span class="pre">Or(x,</span> <span class="pre">y)</span></code> or <code class="docutils literal notranslate"><span class="pre">x</span> <span class="pre">&gt;</span> <span class="pre">1</span></code>, use <code class="docutils literal notranslate"><span class="pre">S.true</span></code>.
Otherwise, use <code class="docutils literal notranslate"><span class="pre">True</span></code>”</p>
<p>In other words, use <code class="docutils literal notranslate"><span class="pre">S.true</span></code> only on those contexts where the
boolean is being used as a symbolic representation of truth.
For example, if the object ends up in the <code class="docutils literal notranslate"><span class="pre">.args</span></code> of any expression,
then it must necessarily be <code class="docutils literal notranslate"><span class="pre">S.true</span></code> instead of <code class="docutils literal notranslate"><span class="pre">True</span></code>, as
elements of <code class="docutils literal notranslate"><span class="pre">.args</span></code> must be <code class="docutils literal notranslate"><span class="pre">Basic</span></code>. On the other hand,
<code class="docutils literal notranslate"><span class="pre">==</span></code> is not a symbolic operation in SymPy, since it always returns
<code class="docutils literal notranslate"><span class="pre">True</span></code> or <code class="docutils literal notranslate"><span class="pre">False</span></code>, and does so in terms of structural equality
rather than mathematical, so it should return <code class="docutils literal notranslate"><span class="pre">True</span></code>. The assumptions
system should use <code class="docutils literal notranslate"><span class="pre">True</span></code> and <code class="docutils literal notranslate"><span class="pre">False</span></code>. Aside from not satisfying
the above rule of thumb, the assumptions system uses a three-valued logic
(<code class="docutils literal notranslate"><span class="pre">True</span></code>, <code class="docutils literal notranslate"><span class="pre">False</span></code>, <code class="docutils literal notranslate"><span class="pre">None</span></code>), whereas <code class="docutils literal notranslate"><span class="pre">S.true</span></code> and <code class="docutils literal notranslate"><span class="pre">S.false</span></code>
represent a two-valued logic. When in doubt, use <code class="docutils literal notranslate"><span class="pre">True</span></code>.</p>
<p>“<code class="docutils literal notranslate"><span class="pre">S.true</span> <span class="pre">==</span> <span class="pre">True</span> <span class="pre">is</span> <span class="pre">True</span></code>.”</p>
<p>While “<code class="docutils literal notranslate"><span class="pre">S.true</span> <span class="pre">is</span> <span class="pre">True</span></code>” is <code class="docutils literal notranslate"><span class="pre">False</span></code>, “<code class="docutils literal notranslate"><span class="pre">S.true</span> <span class="pre">==</span> <span class="pre">True</span></code>”
is <code class="docutils literal notranslate"><span class="pre">True</span></code>, so if there is any doubt over whether a function or
expression will return <code class="docutils literal notranslate"><span class="pre">S.true</span></code> or <code class="docutils literal notranslate"><span class="pre">True</span></code>, just use <code class="docutils literal notranslate"><span class="pre">==</span></code>
instead of <code class="docutils literal notranslate"><span class="pre">is</span></code> to do the comparison, and it will work in either
case.  Finally, for boolean flags, it’s better to just use <code class="docutils literal notranslate"><span class="pre">if</span> <span class="pre">x</span></code>
instead of <code class="docutils literal notranslate"><span class="pre">if</span> <span class="pre">x</span> <span class="pre">is</span> <span class="pre">True</span></code>. To quote PEP 8:</p>
<p>Don’t compare boolean values to <code class="docutils literal notranslate"><span class="pre">True</span></code> or <code class="docutils literal notranslate"><span class="pre">False</span></code>
using <code class="docutils literal notranslate"><span class="pre">==</span></code>.</p>
<ul class="simple">
<li><p>Yes:   <code class="docutils literal notranslate"><span class="pre">if</span> <span class="pre">greeting:</span></code></p></li>
<li><p>No:    <code class="docutils literal notranslate"><span class="pre">if</span> <span class="pre">greeting</span> <span class="pre">==</span> <span class="pre">True:</span></code></p></li>
<li><p>Worse: <code class="docutils literal notranslate"><span class="pre">if</span> <span class="pre">greeting</span> <span class="pre">is</span> <span class="pre">True:</span></code></p></li>
</ul>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">sympify</span><span class="p">,</span> <span class="n">true</span><span class="p">,</span> <span class="n">false</span><span class="p">,</span> <span class="n">Or</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">sympify</span><span class="p">(</span><span class="kc">True</span><span class="p">)</span>
<span class="go">True</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">_</span> <span class="ow">is</span> <span class="kc">True</span><span class="p">,</span> <span class="n">_</span> <span class="ow">is</span> <span class="n">true</span>
<span class="go">(False, True)</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">Or</span><span class="p">(</span><span class="n">true</span><span class="p">,</span> <span class="n">false</span><span class="p">)</span>
<span class="go">True</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">_</span> <span class="ow">is</span> <span class="n">true</span>
<span class="go">True</span>
</pre></div>
</div>
<p>Python operators give a boolean result for true but a
bitwise result for True</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="o">~</span><span class="n">true</span><span class="p">,</span> <span class="o">~</span><span class="kc">True</span>
<span class="go">(False, -2)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">true</span> <span class="o">&gt;&gt;</span> <span class="n">true</span><span class="p">,</span> <span class="kc">True</span> <span class="o">&gt;&gt;</span> <span class="kc">True</span>
<span class="go">(True, 0)</span>
</pre></div>
</div>
<p>Python operators give a boolean result for true but a
bitwise result for True</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="o">~</span><span class="n">true</span><span class="p">,</span> <span class="o">~</span><span class="kc">True</span>
<span class="go">(False, -2)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">true</span> <span class="o">&gt;&gt;</span> <span class="n">true</span><span class="p">,</span> <span class="kc">True</span> <span class="o">&gt;&gt;</span> <span class="kc">True</span>
<span class="go">(True, 0)</span>
</pre></div>
</div>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<p><a class="reference internal" href="#sympy.logic.boolalg.BooleanFalse" title="sympy.logic.boolalg.BooleanFalse"><code class="xref py py-obj docutils literal notranslate"><span class="pre">sympy.logic.boolalg.BooleanFalse</span></code></a></p>
</div>
<dl class="py method">
<dt class="sig sig-object py" id="sympy.logic.boolalg.BooleanTrue.as_set">
<span class="sig-name descname"><span class="pre">as_set</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/logic/boolalg.py#L343-L355"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.logic.boolalg.BooleanTrue.as_set" title="Permalink to this definition">¶</a></dt>
<dd><p>Rewrite logic operators and relationals in terms of real sets.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">true</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">true</span><span class="o">.</span><span class="n">as_set</span><span class="p">()</span>
<span class="go">UniversalSet</span>
</pre></div>
</div>
</dd></dl>

</dd></dl>

<dl class="py class">
<dt class="sig sig-object py" id="sympy.logic.boolalg.BooleanFalse">
<em class="property"><span class="pre">class</span> </em><span class="sig-prename descclassname"><span class="pre">sympy.logic.boolalg.</span></span><span class="sig-name descname"><span class="pre">BooleanFalse</span></span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/logic/boolalg.py#L358-L422"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.logic.boolalg.BooleanFalse" title="Permalink to this definition">¶</a></dt>
<dd><p>SymPy version of False, a singleton that can be accessed via S.false.</p>
<p>This is the SymPy version of False, for use in the logic module. The
primary advantage of using false instead of False is that shorthand boolean
operations like ~ and &gt;&gt; will work as expected on this class, whereas with
False they act bitwise on 0. Functions in the logic module will return this
class when they evaluate to false.</p>
<p class="rubric">Notes</p>
<p>See the notes section in <a class="reference internal" href="#sympy.logic.boolalg.BooleanTrue" title="sympy.logic.boolalg.BooleanTrue"><code class="xref py py-class docutils literal notranslate"><span class="pre">sympy.logic.boolalg.BooleanTrue</span></code></a></p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">sympify</span><span class="p">,</span> <span class="n">true</span><span class="p">,</span> <span class="n">false</span><span class="p">,</span> <span class="n">Or</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">sympify</span><span class="p">(</span><span class="kc">False</span><span class="p">)</span>
<span class="go">False</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">_</span> <span class="ow">is</span> <span class="kc">False</span><span class="p">,</span> <span class="n">_</span> <span class="ow">is</span> <span class="n">false</span>
<span class="go">(False, True)</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">Or</span><span class="p">(</span><span class="n">true</span><span class="p">,</span> <span class="n">false</span><span class="p">)</span>
<span class="go">True</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">_</span> <span class="ow">is</span> <span class="n">true</span>
<span class="go">True</span>
</pre></div>
</div>
<p>Python operators give a boolean result for false but a
bitwise result for False</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="o">~</span><span class="n">false</span><span class="p">,</span> <span class="o">~</span><span class="kc">False</span>
<span class="go">(True, -1)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">false</span> <span class="o">&gt;&gt;</span> <span class="n">false</span><span class="p">,</span> <span class="kc">False</span> <span class="o">&gt;&gt;</span> <span class="kc">False</span>
<span class="go">(True, 0)</span>
</pre></div>
</div>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<p><a class="reference internal" href="#sympy.logic.boolalg.BooleanTrue" title="sympy.logic.boolalg.BooleanTrue"><code class="xref py py-obj docutils literal notranslate"><span class="pre">sympy.logic.boolalg.BooleanTrue</span></code></a></p>
</div>
<dl class="py method">
<dt class="sig sig-object py" id="sympy.logic.boolalg.BooleanFalse.as_set">
<span class="sig-name descname"><span class="pre">as_set</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/logic/boolalg.py#L411-L422"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.logic.boolalg.BooleanFalse.as_set" title="Permalink to this definition">¶</a></dt>
<dd><p>Rewrite logic operators and relationals in terms of real sets.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">false</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">false</span><span class="o">.</span><span class="n">as_set</span><span class="p">()</span>
<span class="go">EmptySet</span>
</pre></div>
</div>
</dd></dl>

</dd></dl>

<dl class="py class">
<dt class="sig sig-object py" id="sympy.logic.boolalg.And">
<em class="property"><span class="pre">class</span> </em><span class="sig-prename descclassname"><span class="pre">sympy.logic.boolalg.</span></span><span class="sig-name descname"><span class="pre">And</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="o"><span class="pre">*</span></span><span class="n"><span class="pre">args</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/logic/boolalg.py#L658-L813"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.logic.boolalg.And" title="Permalink to this definition">¶</a></dt>
<dd><p>Logical AND function.</p>
<p>It evaluates its arguments in order, giving False immediately
if any of them are False, and True if they are all True.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.abc</span> <span class="kn">import</span> <span class="n">x</span><span class="p">,</span> <span class="n">y</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.logic.boolalg</span> <span class="kn">import</span> <span class="n">And</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">x</span> <span class="o">&amp;</span> <span class="n">y</span>
<span class="go">x &amp; y</span>
</pre></div>
</div>
<p class="rubric">Notes</p>
<p>The <code class="docutils literal notranslate"><span class="pre">&amp;</span></code> operator is provided as a convenience, but note that its use
here is different from its normal use in Python, which is bitwise
and. Hence, <code class="docutils literal notranslate"><span class="pre">And(a,</span> <span class="pre">b)</span></code> and <code class="docutils literal notranslate"><span class="pre">a</span> <span class="pre">&amp;</span> <span class="pre">b</span></code> will return different things if
<code class="docutils literal notranslate"><span class="pre">a</span></code> and <code class="docutils literal notranslate"><span class="pre">b</span></code> are integers.</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">And</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">)</span><span class="o">.</span><span class="n">subs</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="mi">1</span><span class="p">)</span>
<span class="go">y</span>
</pre></div>
</div>
</dd></dl>

<dl class="py class">
<dt class="sig sig-object py" id="sympy.logic.boolalg.Or">
<em class="property"><span class="pre">class</span> </em><span class="sig-prename descclassname"><span class="pre">sympy.logic.boolalg.</span></span><span class="sig-name descname"><span class="pre">Or</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="o"><span class="pre">*</span></span><span class="n"><span class="pre">args</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/logic/boolalg.py#L816-L913"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.logic.boolalg.Or" title="Permalink to this definition">¶</a></dt>
<dd><p>Logical OR function</p>
<p>It evaluates its arguments in order, giving True immediately
if any of them are True, and False if they are all False.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.abc</span> <span class="kn">import</span> <span class="n">x</span><span class="p">,</span> <span class="n">y</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.logic.boolalg</span> <span class="kn">import</span> <span class="n">Or</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">x</span> <span class="o">|</span> <span class="n">y</span>
<span class="go">x | y</span>
</pre></div>
</div>
<p class="rubric">Notes</p>
<p>The <code class="docutils literal notranslate"><span class="pre">|</span></code> operator is provided as a convenience, but note that its use
here is different from its normal use in Python, which is bitwise
or. Hence, <code class="docutils literal notranslate"><span class="pre">Or(a,</span> <span class="pre">b)</span></code> and <code class="docutils literal notranslate"><span class="pre">a</span> <span class="pre">|</span> <span class="pre">b</span></code> will return different things if
<code class="docutils literal notranslate"><span class="pre">a</span></code> and <code class="docutils literal notranslate"><span class="pre">b</span></code> are integers.</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">Or</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">)</span><span class="o">.</span><span class="n">subs</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="mi">0</span><span class="p">)</span>
<span class="go">y</span>
</pre></div>
</div>
</dd></dl>

<dl class="py class">
<dt class="sig sig-object py" id="sympy.logic.boolalg.Not">
<em class="property"><span class="pre">class</span> </em><span class="sig-prename descclassname"><span class="pre">sympy.logic.boolalg.</span></span><span class="sig-name descname"><span class="pre">Not</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">arg</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/logic/boolalg.py#L916-L1026"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.logic.boolalg.Not" title="Permalink to this definition">¶</a></dt>
<dd><p>Logical Not function (negation)</p>
<p>Returns True if the statement is False
Returns False if the statement is True</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.logic.boolalg</span> <span class="kn">import</span> <span class="n">Not</span><span class="p">,</span> <span class="n">And</span><span class="p">,</span> <span class="n">Or</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.abc</span> <span class="kn">import</span> <span class="n">x</span><span class="p">,</span> <span class="n">A</span><span class="p">,</span> <span class="n">B</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Not</span><span class="p">(</span><span class="kc">True</span><span class="p">)</span>
<span class="go">False</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Not</span><span class="p">(</span><span class="kc">False</span><span class="p">)</span>
<span class="go">True</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Not</span><span class="p">(</span><span class="n">And</span><span class="p">(</span><span class="kc">True</span><span class="p">,</span> <span class="kc">False</span><span class="p">))</span>
<span class="go">True</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Not</span><span class="p">(</span><span class="n">Or</span><span class="p">(</span><span class="kc">True</span><span class="p">,</span> <span class="kc">False</span><span class="p">))</span>
<span class="go">False</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Not</span><span class="p">(</span><span class="n">And</span><span class="p">(</span><span class="n">And</span><span class="p">(</span><span class="kc">True</span><span class="p">,</span> <span class="n">x</span><span class="p">),</span> <span class="n">Or</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="kc">False</span><span class="p">)))</span>
<span class="go">~x</span>
<span class="gp">&gt;&gt;&gt; </span><span class="o">~</span><span class="n">x</span>
<span class="go">~x</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Not</span><span class="p">(</span><span class="n">And</span><span class="p">(</span><span class="n">Or</span><span class="p">(</span><span class="n">A</span><span class="p">,</span> <span class="n">B</span><span class="p">),</span> <span class="n">Or</span><span class="p">(</span><span class="o">~</span><span class="n">A</span><span class="p">,</span> <span class="o">~</span><span class="n">B</span><span class="p">)))</span>
<span class="go">~((A | B) &amp; (~A | ~B))</span>
</pre></div>
</div>
<p class="rubric">Notes</p>
<ul class="simple">
<li><p>The <code class="docutils literal notranslate"><span class="pre">~</span></code> operator is provided as a convenience, but note that its use
here is different from its normal use in Python, which is bitwise
not. In particular, <code class="docutils literal notranslate"><span class="pre">~a</span></code> and <code class="docutils literal notranslate"><span class="pre">Not(a)</span></code> will be different if <code class="docutils literal notranslate"><span class="pre">a</span></code> is
an integer. Furthermore, since bools in Python subclass from <code class="docutils literal notranslate"><span class="pre">int</span></code>,
<code class="docutils literal notranslate"><span class="pre">~True</span></code> is the same as <code class="docutils literal notranslate"><span class="pre">~1</span></code> which is <code class="docutils literal notranslate"><span class="pre">-2</span></code>, which has a boolean
value of True.  To avoid this issue, use the SymPy boolean types
<code class="docutils literal notranslate"><span class="pre">true</span></code> and <code class="docutils literal notranslate"><span class="pre">false</span></code>.</p></li>
</ul>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">true</span>
<span class="gp">&gt;&gt;&gt; </span><span class="o">~</span><span class="kc">True</span>
<span class="go">-2</span>
<span class="gp">&gt;&gt;&gt; </span><span class="o">~</span><span class="n">true</span>
<span class="go">False</span>
</pre></div>
</div>
</dd></dl>

<dl class="py class">
<dt class="sig sig-object py" id="sympy.logic.boolalg.Xor">
<em class="property"><span class="pre">class</span> </em><span class="sig-prename descclassname"><span class="pre">sympy.logic.boolalg.</span></span><span class="sig-name descname"><span class="pre">Xor</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="o"><span class="pre">*</span></span><span class="n"><span class="pre">args</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/logic/boolalg.py#L1029-L1161"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.logic.boolalg.Xor" title="Permalink to this definition">¶</a></dt>
<dd><p>Logical XOR (exclusive OR) function.</p>
<p>Returns True if an odd number of the arguments are True and the rest are
False.</p>
<p>Returns False if an even number of the arguments are True and the rest are
False.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.logic.boolalg</span> <span class="kn">import</span> <span class="n">Xor</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">symbols</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">x</span><span class="p">,</span> <span class="n">y</span> <span class="o">=</span> <span class="n">symbols</span><span class="p">(</span><span class="s1">&#39;x y&#39;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Xor</span><span class="p">(</span><span class="kc">True</span><span class="p">,</span> <span class="kc">False</span><span class="p">)</span>
<span class="go">True</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Xor</span><span class="p">(</span><span class="kc">True</span><span class="p">,</span> <span class="kc">True</span><span class="p">)</span>
<span class="go">False</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Xor</span><span class="p">(</span><span class="kc">True</span><span class="p">,</span> <span class="kc">False</span><span class="p">,</span> <span class="kc">True</span><span class="p">,</span> <span class="kc">True</span><span class="p">,</span> <span class="kc">False</span><span class="p">)</span>
<span class="go">True</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Xor</span><span class="p">(</span><span class="kc">True</span><span class="p">,</span> <span class="kc">False</span><span class="p">,</span> <span class="kc">True</span><span class="p">,</span> <span class="kc">False</span><span class="p">)</span>
<span class="go">False</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">x</span> <span class="o">^</span> <span class="n">y</span>
<span class="go">x ^ y</span>
</pre></div>
</div>
<p class="rubric">Notes</p>
<p>The <code class="docutils literal notranslate"><span class="pre">^</span></code> operator is provided as a convenience, but note that its use
here is different from its normal use in Python, which is bitwise xor. In
particular, <code class="docutils literal notranslate"><span class="pre">a</span> <span class="pre">^</span> <span class="pre">b</span></code> and <code class="docutils literal notranslate"><span class="pre">Xor(a,</span> <span class="pre">b)</span></code> will be different if <code class="docutils literal notranslate"><span class="pre">a</span></code> and
<code class="docutils literal notranslate"><span class="pre">b</span></code> are integers.</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">Xor</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">)</span><span class="o">.</span><span class="n">subs</span><span class="p">(</span><span class="n">y</span><span class="p">,</span> <span class="mi">0</span><span class="p">)</span>
<span class="go">x</span>
</pre></div>
</div>
</dd></dl>

<dl class="py class">
<dt class="sig sig-object py" id="sympy.logic.boolalg.Nand">
<em class="property"><span class="pre">class</span> </em><span class="sig-prename descclassname"><span class="pre">sympy.logic.boolalg.</span></span><span class="sig-name descname"><span class="pre">Nand</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="o"><span class="pre">*</span></span><span class="n"><span class="pre">args</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/logic/boolalg.py#L1164-L1190"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.logic.boolalg.Nand" title="Permalink to this definition">¶</a></dt>
<dd><p>Logical NAND function.</p>
<p>It evaluates its arguments in order, giving True immediately if any
of them are False, and False if they are all True.</p>
<p>Returns True if any of the arguments are False
Returns False if all arguments are True</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.logic.boolalg</span> <span class="kn">import</span> <span class="n">Nand</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">symbols</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">x</span><span class="p">,</span> <span class="n">y</span> <span class="o">=</span> <span class="n">symbols</span><span class="p">(</span><span class="s1">&#39;x y&#39;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Nand</span><span class="p">(</span><span class="kc">False</span><span class="p">,</span> <span class="kc">True</span><span class="p">)</span>
<span class="go">True</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Nand</span><span class="p">(</span><span class="kc">True</span><span class="p">,</span> <span class="kc">True</span><span class="p">)</span>
<span class="go">False</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Nand</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">)</span>
<span class="go">~(x &amp; y)</span>
</pre></div>
</div>
</dd></dl>

<dl class="py class">
<dt class="sig sig-object py" id="sympy.logic.boolalg.Nor">
<em class="property"><span class="pre">class</span> </em><span class="sig-prename descclassname"><span class="pre">sympy.logic.boolalg.</span></span><span class="sig-name descname"><span class="pre">Nor</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="o"><span class="pre">*</span></span><span class="n"><span class="pre">args</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/logic/boolalg.py#L1193-L1224"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.logic.boolalg.Nor" title="Permalink to this definition">¶</a></dt>
<dd><p>Logical NOR function.</p>
<p>It evaluates its arguments in order, giving False immediately if any
of them are True, and True if they are all False.</p>
<p>Returns False if any argument is True
Returns True if all arguments are False</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.logic.boolalg</span> <span class="kn">import</span> <span class="n">Nor</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">symbols</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">x</span><span class="p">,</span> <span class="n">y</span> <span class="o">=</span> <span class="n">symbols</span><span class="p">(</span><span class="s1">&#39;x y&#39;</span><span class="p">)</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">Nor</span><span class="p">(</span><span class="kc">True</span><span class="p">,</span> <span class="kc">False</span><span class="p">)</span>
<span class="go">False</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Nor</span><span class="p">(</span><span class="kc">True</span><span class="p">,</span> <span class="kc">True</span><span class="p">)</span>
<span class="go">False</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Nor</span><span class="p">(</span><span class="kc">False</span><span class="p">,</span> <span class="kc">True</span><span class="p">)</span>
<span class="go">False</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Nor</span><span class="p">(</span><span class="kc">False</span><span class="p">,</span> <span class="kc">False</span><span class="p">)</span>
<span class="go">True</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Nor</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">)</span>
<span class="go">~(x | y)</span>
</pre></div>
</div>
</dd></dl>

<dl class="py class">
<dt class="sig sig-object py" id="sympy.logic.boolalg.Implies">
<em class="property"><span class="pre">class</span> </em><span class="sig-prename descclassname"><span class="pre">sympy.logic.boolalg.</span></span><span class="sig-name descname"><span class="pre">Implies</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="o"><span class="pre">*</span></span><span class="n"><span class="pre">args</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/logic/boolalg.py#L1258-L1338"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.logic.boolalg.Implies" title="Permalink to this definition">¶</a></dt>
<dd><p>Logical implication.</p>
<p>A implies B is equivalent to !A v B</p>
<p>Accepts two Boolean arguments; A and B.
Returns False if A is True and B is False
Returns True otherwise.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.logic.boolalg</span> <span class="kn">import</span> <span class="n">Implies</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">symbols</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">x</span><span class="p">,</span> <span class="n">y</span> <span class="o">=</span> <span class="n">symbols</span><span class="p">(</span><span class="s1">&#39;x y&#39;</span><span class="p">)</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">Implies</span><span class="p">(</span><span class="kc">True</span><span class="p">,</span> <span class="kc">False</span><span class="p">)</span>
<span class="go">False</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Implies</span><span class="p">(</span><span class="kc">False</span><span class="p">,</span> <span class="kc">False</span><span class="p">)</span>
<span class="go">True</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Implies</span><span class="p">(</span><span class="kc">True</span><span class="p">,</span> <span class="kc">True</span><span class="p">)</span>
<span class="go">True</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Implies</span><span class="p">(</span><span class="kc">False</span><span class="p">,</span> <span class="kc">True</span><span class="p">)</span>
<span class="go">True</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">x</span> <span class="o">&gt;&gt;</span> <span class="n">y</span>
<span class="go">Implies(x, y)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">y</span> <span class="o">&lt;&lt;</span> <span class="n">x</span>
<span class="go">Implies(x, y)</span>
</pre></div>
</div>
<p class="rubric">Notes</p>
<p>The <code class="docutils literal notranslate"><span class="pre">&gt;&gt;</span></code> and <code class="docutils literal notranslate"><span class="pre">&lt;&lt;</span></code> operators are provided as a convenience, but note
that their use here is different from their normal use in Python, which is
bit shifts. Hence, <code class="docutils literal notranslate"><span class="pre">Implies(a,</span> <span class="pre">b)</span></code> and <code class="docutils literal notranslate"><span class="pre">a</span> <span class="pre">&gt;&gt;</span> <span class="pre">b</span></code> will return different
things if <code class="docutils literal notranslate"><span class="pre">a</span></code> and <code class="docutils literal notranslate"><span class="pre">b</span></code> are integers.  In particular, since Python
considers <code class="docutils literal notranslate"><span class="pre">True</span></code> and <code class="docutils literal notranslate"><span class="pre">False</span></code> to be integers, <code class="docutils literal notranslate"><span class="pre">True</span> <span class="pre">&gt;&gt;</span> <span class="pre">True</span></code> will be
the same as <code class="docutils literal notranslate"><span class="pre">1</span> <span class="pre">&gt;&gt;</span> <span class="pre">1</span></code>, i.e., 0, which has a truth value of False.  To
avoid this issue, use the SymPy objects <code class="docutils literal notranslate"><span class="pre">true</span></code> and <code class="docutils literal notranslate"><span class="pre">false</span></code>.</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">true</span><span class="p">,</span> <span class="n">false</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kc">True</span> <span class="o">&gt;&gt;</span> <span class="kc">False</span>
<span class="go">1</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">true</span> <span class="o">&gt;&gt;</span> <span class="n">false</span>
<span class="go">False</span>
</pre></div>
</div>
</dd></dl>

<dl class="py class">
<dt class="sig sig-object py" id="sympy.logic.boolalg.Equivalent">
<em class="property"><span class="pre">class</span> </em><span class="sig-prename descclassname"><span class="pre">sympy.logic.boolalg.</span></span><span class="sig-name descname"><span class="pre">Equivalent</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="o"><span class="pre">*</span></span><span class="n"><span class="pre">args</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/logic/boolalg.py#L1341-L1420"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.logic.boolalg.Equivalent" title="Permalink to this definition">¶</a></dt>
<dd><p>Equivalence relation.</p>
<p>Equivalent(A, B) is True iff A and B are both True or both False</p>
<p>Returns True if all of the arguments are logically equivalent.
Returns False otherwise.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.logic.boolalg</span> <span class="kn">import</span> <span class="n">Equivalent</span><span class="p">,</span> <span class="n">And</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.abc</span> <span class="kn">import</span> <span class="n">x</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Equivalent</span><span class="p">(</span><span class="kc">False</span><span class="p">,</span> <span class="kc">False</span><span class="p">,</span> <span class="kc">False</span><span class="p">)</span>
<span class="go">True</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Equivalent</span><span class="p">(</span><span class="kc">True</span><span class="p">,</span> <span class="kc">False</span><span class="p">,</span> <span class="kc">False</span><span class="p">)</span>
<span class="go">False</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Equivalent</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">And</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="kc">True</span><span class="p">))</span>
<span class="go">True</span>
</pre></div>
</div>
</dd></dl>

<dl class="py class">
<dt class="sig sig-object py" id="sympy.logic.boolalg.ITE">
<em class="property"><span class="pre">class</span> </em><span class="sig-prename descclassname"><span class="pre">sympy.logic.boolalg.</span></span><span class="sig-name descname"><span class="pre">ITE</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="o"><span class="pre">*</span></span><span class="n"><span class="pre">args</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/logic/boolalg.py#L1423-L1534"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.logic.boolalg.ITE" title="Permalink to this definition">¶</a></dt>
<dd><p>If then else clause.</p>
<p>ITE(A, B, C) evaluates and returns the result of B if A is true
else it returns the result of C. All args must be Booleans.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.logic.boolalg</span> <span class="kn">import</span> <span class="n">ITE</span><span class="p">,</span> <span class="n">And</span><span class="p">,</span> <span class="n">Xor</span><span class="p">,</span> <span class="n">Or</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.abc</span> <span class="kn">import</span> <span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">,</span> <span class="n">z</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">ITE</span><span class="p">(</span><span class="kc">True</span><span class="p">,</span> <span class="kc">False</span><span class="p">,</span> <span class="kc">True</span><span class="p">)</span>
<span class="go">False</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">ITE</span><span class="p">(</span><span class="n">Or</span><span class="p">(</span><span class="kc">True</span><span class="p">,</span> <span class="kc">False</span><span class="p">),</span> <span class="n">And</span><span class="p">(</span><span class="kc">True</span><span class="p">,</span> <span class="kc">True</span><span class="p">),</span> <span class="n">Xor</span><span class="p">(</span><span class="kc">True</span><span class="p">,</span> <span class="kc">True</span><span class="p">))</span>
<span class="go">True</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">ITE</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">,</span> <span class="n">z</span><span class="p">)</span>
<span class="go">ITE(x, y, z)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">ITE</span><span class="p">(</span><span class="kc">True</span><span class="p">,</span> <span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">)</span>
<span class="go">x</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">ITE</span><span class="p">(</span><span class="kc">False</span><span class="p">,</span> <span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">)</span>
<span class="go">y</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">ITE</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">,</span> <span class="n">y</span><span class="p">)</span>
<span class="go">y</span>
</pre></div>
</div>
<p>Trying to use non-Boolean args will generate a TypeError:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">ITE</span><span class="p">(</span><span class="kc">True</span><span class="p">,</span> <span class="p">[],</span> <span class="p">())</span>
<span class="gt">Traceback (most recent call last):</span>
<span class="c">...</span>
<span class="gr">TypeError</span>: <span class="n">expecting bool, Boolean or ITE, not `[]`</span>
</pre></div>
</div>
</dd></dl>

<p>The following functions can be used to handle Conjunctive and Disjunctive Normal
forms-</p>
<dl class="py function">
<dt class="sig sig-object py" id="sympy.logic.boolalg.to_cnf">
<span class="sig-prename descclassname"><span class="pre">sympy.logic.boolalg.</span></span><span class="sig-name descname"><span class="pre">to_cnf</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">expr</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">simplify</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">force</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/logic/boolalg.py#L1746-L1785"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.logic.boolalg.to_cnf" title="Permalink to this definition">¶</a></dt>
<dd><p>Convert a propositional logical sentence s to conjunctive normal
form: ((A | ~B | …) &amp; (B | C | …) &amp; …).
If simplify is True, the expr is evaluated to its simplest CNF
form using the Quine-McCluskey algorithm; this may take a long
time if there are more than 8 variables and requires that the
<code class="docutils literal notranslate"><span class="pre">force</span></code> flag be set to True (default is False).</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.logic.boolalg</span> <span class="kn">import</span> <span class="n">to_cnf</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.abc</span> <span class="kn">import</span> <span class="n">A</span><span class="p">,</span> <span class="n">B</span><span class="p">,</span> <span class="n">D</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">to_cnf</span><span class="p">(</span><span class="o">~</span><span class="p">(</span><span class="n">A</span> <span class="o">|</span> <span class="n">B</span><span class="p">)</span> <span class="o">|</span> <span class="n">D</span><span class="p">)</span>
<span class="go">(D | ~A) &amp; (D | ~B)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">to_cnf</span><span class="p">((</span><span class="n">A</span> <span class="o">|</span> <span class="n">B</span><span class="p">)</span> <span class="o">&amp;</span> <span class="p">(</span><span class="n">A</span> <span class="o">|</span> <span class="o">~</span><span class="n">A</span><span class="p">),</span> <span class="kc">True</span><span class="p">)</span>
<span class="go">A | B</span>
</pre></div>
</div>
</dd></dl>

<dl class="py function">
<dt class="sig sig-object py" id="sympy.logic.boolalg.to_dnf">
<span class="sig-prename descclassname"><span class="pre">sympy.logic.boolalg.</span></span><span class="sig-name descname"><span class="pre">to_dnf</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">expr</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">simplify</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">force</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/logic/boolalg.py#L1788-L1825"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.logic.boolalg.to_dnf" title="Permalink to this definition">¶</a></dt>
<dd><p>Convert a propositional logical sentence s to disjunctive normal
form: ((A &amp; ~B &amp; …) | (B &amp; C &amp; …) | …).
If simplify is True, the expr is evaluated to its simplest DNF form using
the Quine-McCluskey algorithm; this may take a long
time if there are more than 8 variables and requires that the
<code class="docutils literal notranslate"><span class="pre">force</span></code> flag be set to True (default is False).</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.logic.boolalg</span> <span class="kn">import</span> <span class="n">to_dnf</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.abc</span> <span class="kn">import</span> <span class="n">A</span><span class="p">,</span> <span class="n">B</span><span class="p">,</span> <span class="n">C</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">to_dnf</span><span class="p">(</span><span class="n">B</span> <span class="o">&amp;</span> <span class="p">(</span><span class="n">A</span> <span class="o">|</span> <span class="n">C</span><span class="p">))</span>
<span class="go">(A &amp; B) | (B &amp; C)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">to_dnf</span><span class="p">((</span><span class="n">A</span> <span class="o">&amp;</span> <span class="n">B</span><span class="p">)</span> <span class="o">|</span> <span class="p">(</span><span class="n">A</span> <span class="o">&amp;</span> <span class="o">~</span><span class="n">B</span><span class="p">)</span> <span class="o">|</span> <span class="p">(</span><span class="n">B</span> <span class="o">&amp;</span> <span class="n">C</span><span class="p">)</span> <span class="o">|</span> <span class="p">(</span><span class="o">~</span><span class="n">B</span> <span class="o">&amp;</span> <span class="n">C</span><span class="p">),</span> <span class="kc">True</span><span class="p">)</span>
<span class="go">A | C</span>
</pre></div>
</div>
</dd></dl>

<dl class="py function">
<dt class="sig sig-object py" id="sympy.logic.boolalg.is_cnf">
<span class="sig-prename descclassname"><span class="pre">sympy.logic.boolalg.</span></span><span class="sig-name descname"><span class="pre">is_cnf</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">expr</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/logic/boolalg.py#L1930-L1947"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.logic.boolalg.is_cnf" title="Permalink to this definition">¶</a></dt>
<dd><p>Test whether or not an expression is in conjunctive normal form.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.logic.boolalg</span> <span class="kn">import</span> <span class="n">is_cnf</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.abc</span> <span class="kn">import</span> <span class="n">A</span><span class="p">,</span> <span class="n">B</span><span class="p">,</span> <span class="n">C</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">is_cnf</span><span class="p">(</span><span class="n">A</span> <span class="o">|</span> <span class="n">B</span> <span class="o">|</span> <span class="n">C</span><span class="p">)</span>
<span class="go">True</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">is_cnf</span><span class="p">(</span><span class="n">A</span> <span class="o">&amp;</span> <span class="n">B</span> <span class="o">&amp;</span> <span class="n">C</span><span class="p">)</span>
<span class="go">True</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">is_cnf</span><span class="p">((</span><span class="n">A</span> <span class="o">&amp;</span> <span class="n">B</span><span class="p">)</span> <span class="o">|</span> <span class="n">C</span><span class="p">)</span>
<span class="go">False</span>
</pre></div>
</div>
</dd></dl>

<dl class="py function">
<dt class="sig sig-object py" id="sympy.logic.boolalg.is_dnf">
<span class="sig-prename descclassname"><span class="pre">sympy.logic.boolalg.</span></span><span class="sig-name descname"><span class="pre">is_dnf</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">expr</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/logic/boolalg.py#L1950-L1969"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.logic.boolalg.is_dnf" title="Permalink to this definition">¶</a></dt>
<dd><p>Test whether or not an expression is in disjunctive normal form.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.logic.boolalg</span> <span class="kn">import</span> <span class="n">is_dnf</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.abc</span> <span class="kn">import</span> <span class="n">A</span><span class="p">,</span> <span class="n">B</span><span class="p">,</span> <span class="n">C</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">is_dnf</span><span class="p">(</span><span class="n">A</span> <span class="o">|</span> <span class="n">B</span> <span class="o">|</span> <span class="n">C</span><span class="p">)</span>
<span class="go">True</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">is_dnf</span><span class="p">(</span><span class="n">A</span> <span class="o">&amp;</span> <span class="n">B</span> <span class="o">&amp;</span> <span class="n">C</span><span class="p">)</span>
<span class="go">True</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">is_dnf</span><span class="p">((</span><span class="n">A</span> <span class="o">&amp;</span> <span class="n">B</span><span class="p">)</span> <span class="o">|</span> <span class="n">C</span><span class="p">)</span>
<span class="go">True</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">is_dnf</span><span class="p">(</span><span class="n">A</span> <span class="o">&amp;</span> <span class="p">(</span><span class="n">B</span> <span class="o">|</span> <span class="n">C</span><span class="p">))</span>
<span class="go">False</span>
</pre></div>
</div>
</dd></dl>

</section>
<section id="simplification-and-equivalence-testing">
<h2>Simplification and equivalence-testing<a class="headerlink" href="#simplification-and-equivalence-testing" title="Permalink to this headline">¶</a></h2>
<dl class="py function">
<dt class="sig sig-object py" id="sympy.logic.boolalg.simplify_logic">
<span class="sig-prename descclassname"><span class="pre">sympy.logic.boolalg.</span></span><span class="sig-name descname"><span class="pre">simplify_logic</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">expr</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">form</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">deep</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">True</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">force</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/logic/boolalg.py#L2825-L2908"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.logic.boolalg.simplify_logic" title="Permalink to this definition">¶</a></dt>
<dd><p>This function simplifies a boolean function to its simplified version
in SOP or POS form. The return type is an Or or And object in SymPy.</p>
<dl class="field-list">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>expr</strong> : string or boolean expression</p>
<p><strong>form</strong> : string (‘cnf’ or ‘dnf’) or None (default).</p>
<blockquote>
<div><p>If ‘cnf’ or ‘dnf’, the simplest expression in the corresponding
normal form is returned; if None, the answer is returned
according to the form with fewest args (in CNF by default).</p>
</div></blockquote>
<p><strong>deep</strong> : boolean (default True)</p>
<blockquote>
<div><p>Indicates whether to recursively simplify any
non-boolean functions contained within the input.</p>
</div></blockquote>
<p><strong>force</strong> : boolean (default False)</p>
<blockquote>
<div><p>As the simplifications require exponential time in the number
of variables, there is by default a limit on expressions with
8 variables. When the expression has more than 8 variables
only symbolical simplification (controlled by <code class="docutils literal notranslate"><span class="pre">deep</span></code>) is
made. By setting force to <code class="docutils literal notranslate"><span class="pre">True</span></code>, this limit is removed. Be
aware that this can lead to very long simplification times.</p>
</div></blockquote>
</dd>
</dl>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.logic</span> <span class="kn">import</span> <span class="n">simplify_logic</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.abc</span> <span class="kn">import</span> <span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">,</span> <span class="n">z</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">S</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">b</span> <span class="o">=</span> <span class="p">(</span><span class="o">~</span><span class="n">x</span> <span class="o">&amp;</span> <span class="o">~</span><span class="n">y</span> <span class="o">&amp;</span> <span class="o">~</span><span class="n">z</span><span class="p">)</span> <span class="o">|</span> <span class="p">(</span> <span class="o">~</span><span class="n">x</span> <span class="o">&amp;</span> <span class="o">~</span><span class="n">y</span> <span class="o">&amp;</span> <span class="n">z</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">simplify_logic</span><span class="p">(</span><span class="n">b</span><span class="p">)</span>
<span class="go">~x &amp; ~y</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">S</span><span class="p">(</span><span class="n">b</span><span class="p">)</span>
<span class="go">(z &amp; ~x &amp; ~y) | (~x &amp; ~y &amp; ~z)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">simplify_logic</span><span class="p">(</span><span class="n">_</span><span class="p">)</span>
<span class="go">~x &amp; ~y</span>
</pre></div>
</div>
</dd></dl>

<p>SymPy’s simplify() function can also be used to simplify logic expressions to their
simplest forms.</p>
<dl class="py function">
<dt class="sig sig-object py" id="sympy.logic.boolalg.bool_map">
<span class="sig-prename descclassname"><span class="pre">sympy.logic.boolalg.</span></span><span class="sig-name descname"><span class="pre">bool_map</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">bool1</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">bool2</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/logic/boolalg.py#L2982-L3063"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.logic.boolalg.bool_map" title="Permalink to this definition">¶</a></dt>
<dd><p>Return the simplified version of bool1, and the mapping of variables
that makes the two expressions bool1 and bool2 represent the same
logical behaviour for some correspondence between the variables
of each.
If more than one mappings of this sort exist, one of them
is returned.
For example, And(x, y) is logically equivalent to And(a, b) for
the mapping {x: a, y:b} or {x: b, y:a}.
If no such mapping exists, return False.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">SOPform</span><span class="p">,</span> <span class="n">bool_map</span><span class="p">,</span> <span class="n">Or</span><span class="p">,</span> <span class="n">And</span><span class="p">,</span> <span class="n">Not</span><span class="p">,</span> <span class="n">Xor</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.abc</span> <span class="kn">import</span> <span class="n">w</span><span class="p">,</span> <span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">,</span> <span class="n">z</span><span class="p">,</span> <span class="n">a</span><span class="p">,</span> <span class="n">b</span><span class="p">,</span> <span class="n">c</span><span class="p">,</span> <span class="n">d</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">function1</span> <span class="o">=</span> <span class="n">SOPform</span><span class="p">([</span><span class="n">x</span><span class="p">,</span> <span class="n">z</span><span class="p">,</span> <span class="n">y</span><span class="p">],[[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">],</span> <span class="p">[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">]])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">function2</span> <span class="o">=</span> <span class="n">SOPform</span><span class="p">([</span><span class="n">a</span><span class="p">,</span> <span class="n">b</span><span class="p">,</span> <span class="n">c</span><span class="p">],[[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">],</span> <span class="p">[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">]])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">bool_map</span><span class="p">(</span><span class="n">function1</span><span class="p">,</span> <span class="n">function2</span><span class="p">)</span>
<span class="go">(y &amp; ~z, {y: a, z: b})</span>
</pre></div>
</div>
<p>The results are not necessarily unique, but they are canonical. Here,
<code class="docutils literal notranslate"><span class="pre">(w,</span> <span class="pre">z)</span></code> could be <code class="docutils literal notranslate"><span class="pre">(a,</span> <span class="pre">d)</span></code> or <code class="docutils literal notranslate"><span class="pre">(d,</span> <span class="pre">a)</span></code>:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">eq</span> <span class="o">=</span>  <span class="n">Or</span><span class="p">(</span><span class="n">And</span><span class="p">(</span><span class="n">Not</span><span class="p">(</span><span class="n">y</span><span class="p">),</span> <span class="n">w</span><span class="p">),</span> <span class="n">And</span><span class="p">(</span><span class="n">Not</span><span class="p">(</span><span class="n">y</span><span class="p">),</span> <span class="n">z</span><span class="p">),</span> <span class="n">And</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">eq2</span> <span class="o">=</span> <span class="n">Or</span><span class="p">(</span><span class="n">And</span><span class="p">(</span><span class="n">Not</span><span class="p">(</span><span class="n">c</span><span class="p">),</span> <span class="n">a</span><span class="p">),</span> <span class="n">And</span><span class="p">(</span><span class="n">Not</span><span class="p">(</span><span class="n">c</span><span class="p">),</span> <span class="n">d</span><span class="p">),</span> <span class="n">And</span><span class="p">(</span><span class="n">b</span><span class="p">,</span> <span class="n">c</span><span class="p">))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">bool_map</span><span class="p">(</span><span class="n">eq</span><span class="p">,</span> <span class="n">eq2</span><span class="p">)</span>
<span class="go">((x &amp; y) | (w &amp; ~y) | (z &amp; ~y), {w: a, x: b, y: c, z: d})</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">eq</span> <span class="o">=</span> <span class="n">And</span><span class="p">(</span><span class="n">Xor</span><span class="p">(</span><span class="n">a</span><span class="p">,</span> <span class="n">b</span><span class="p">),</span> <span class="n">c</span><span class="p">,</span> <span class="n">And</span><span class="p">(</span><span class="n">c</span><span class="p">,</span><span class="n">d</span><span class="p">))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">bool_map</span><span class="p">(</span><span class="n">eq</span><span class="p">,</span> <span class="n">eq</span><span class="o">.</span><span class="n">subs</span><span class="p">(</span><span class="n">c</span><span class="p">,</span> <span class="n">x</span><span class="p">))</span>
<span class="go">(c &amp; d &amp; (a | b) &amp; (~a | ~b), {a: a, b: b, c: d, d: x})</span>
</pre></div>
</div>
</dd></dl>

</section>
<section id="module-sympy.logic.inference">
<span id="inference"></span><h2>Inference<a class="headerlink" href="#module-sympy.logic.inference" title="Permalink to this headline">¶</a></h2>
<p>This module implements some inference routines in propositional logic.</p>
<p>The function satisfiable will test that a given Boolean expression is satisfiable,
that is, you can assign values to the variables to make the sentence <span class="math notranslate nohighlight">\(True\)</span>.</p>
<p>For example, the expression <code class="docutils literal notranslate"><span class="pre">x</span> <span class="pre">&amp;</span> <span class="pre">~x</span></code> is not satisfiable, since there are no
values for <code class="docutils literal notranslate"><span class="pre">x</span></code> that make this sentence <code class="docutils literal notranslate"><span class="pre">True</span></code>. On the other hand, <code class="docutils literal notranslate"><span class="pre">(x</span>
<span class="pre">|</span> <span class="pre">y)</span> <span class="pre">&amp;</span> <span class="pre">(x</span> <span class="pre">|</span> <span class="pre">~y)</span> <span class="pre">&amp;</span> <span class="pre">(~x</span> <span class="pre">|</span> <span class="pre">y)</span></code> is satisfiable with both <code class="docutils literal notranslate"><span class="pre">x</span></code> and <code class="docutils literal notranslate"><span class="pre">y</span></code> being
<code class="docutils literal notranslate"><span class="pre">True</span></code>.</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.logic.inference</span> <span class="kn">import</span> <span class="n">satisfiable</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">Symbol</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">x</span> <span class="o">=</span> <span class="n">Symbol</span><span class="p">(</span><span class="s1">&#39;x&#39;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">y</span> <span class="o">=</span> <span class="n">Symbol</span><span class="p">(</span><span class="s1">&#39;y&#39;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">satisfiable</span><span class="p">(</span><span class="n">x</span> <span class="o">&amp;</span> <span class="o">~</span><span class="n">x</span><span class="p">)</span>
<span class="go">False</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">satisfiable</span><span class="p">((</span><span class="n">x</span> <span class="o">|</span> <span class="n">y</span><span class="p">)</span> <span class="o">&amp;</span> <span class="p">(</span><span class="n">x</span> <span class="o">|</span> <span class="o">~</span><span class="n">y</span><span class="p">)</span> <span class="o">&amp;</span> <span class="p">(</span><span class="o">~</span><span class="n">x</span> <span class="o">|</span> <span class="n">y</span><span class="p">))</span>
<span class="go">{x: True, y: True}</span>
</pre></div>
</div>
<p>As you see, when a sentence is satisfiable, it returns a model that makes that
sentence <code class="docutils literal notranslate"><span class="pre">True</span></code>. If it is not satisfiable it will return <code class="docutils literal notranslate"><span class="pre">False</span></code>.</p>
<dl class="py function">
<dt class="sig sig-object py" id="sympy.logic.inference.satisfiable">
<span class="sig-prename descclassname"><span class="pre">sympy.logic.inference.</span></span><span class="sig-name descname"><span class="pre">satisfiable</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">expr</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">algorithm</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">all_models</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">minimal</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/logic/inference.py#L38-L108"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.logic.inference.satisfiable" title="Permalink to this definition">¶</a></dt>
<dd><p>Check satisfiability of a propositional sentence.
Returns a model when it succeeds.
Returns {true: true} for trivially true expressions.</p>
<p>On setting all_models to True, if given expr is satisfiable then
returns a generator of models. However, if expr is unsatisfiable
then returns a generator containing the single element False.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.abc</span> <span class="kn">import</span> <span class="n">A</span><span class="p">,</span> <span class="n">B</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.logic.inference</span> <span class="kn">import</span> <span class="n">satisfiable</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">satisfiable</span><span class="p">(</span><span class="n">A</span> <span class="o">&amp;</span> <span class="o">~</span><span class="n">B</span><span class="p">)</span>
<span class="go">{A: True, B: False}</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">satisfiable</span><span class="p">(</span><span class="n">A</span> <span class="o">&amp;</span> <span class="o">~</span><span class="n">A</span><span class="p">)</span>
<span class="go">False</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">satisfiable</span><span class="p">(</span><span class="kc">True</span><span class="p">)</span>
<span class="go">{True: True}</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">next</span><span class="p">(</span><span class="n">satisfiable</span><span class="p">(</span><span class="n">A</span> <span class="o">&amp;</span> <span class="o">~</span><span class="n">A</span><span class="p">,</span> <span class="n">all_models</span><span class="o">=</span><span class="kc">True</span><span class="p">))</span>
<span class="go">False</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">models</span> <span class="o">=</span> <span class="n">satisfiable</span><span class="p">((</span><span class="n">A</span> <span class="o">&gt;&gt;</span> <span class="n">B</span><span class="p">)</span> <span class="o">&amp;</span> <span class="n">B</span><span class="p">,</span> <span class="n">all_models</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">next</span><span class="p">(</span><span class="n">models</span><span class="p">)</span>
<span class="go">{A: False, B: True}</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">next</span><span class="p">(</span><span class="n">models</span><span class="p">)</span>
<span class="go">{A: True, B: True}</span>
<span class="gp">&gt;&gt;&gt; </span><span class="k">def</span> <span class="nf">use_models</span><span class="p">(</span><span class="n">models</span><span class="p">):</span>
<span class="gp">... </span>    <span class="k">for</span> <span class="n">model</span> <span class="ow">in</span> <span class="n">models</span><span class="p">:</span>
<span class="gp">... </span>        <span class="k">if</span> <span class="n">model</span><span class="p">:</span>
<span class="gp">... </span>            <span class="c1"># Do something with the model.</span>
<span class="gp">... </span>            <span class="nb">print</span><span class="p">(</span><span class="n">model</span><span class="p">)</span>
<span class="gp">... </span>        <span class="k">else</span><span class="p">:</span>
<span class="gp">... </span>            <span class="c1"># Given expr is unsatisfiable.</span>
<span class="gp">... </span>            <span class="nb">print</span><span class="p">(</span><span class="s2">&quot;UNSAT&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">use_models</span><span class="p">(</span><span class="n">satisfiable</span><span class="p">(</span><span class="n">A</span> <span class="o">&gt;&gt;</span> <span class="o">~</span><span class="n">A</span><span class="p">,</span> <span class="n">all_models</span><span class="o">=</span><span class="kc">True</span><span class="p">))</span>
<span class="go">{A: False}</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">use_models</span><span class="p">(</span><span class="n">satisfiable</span><span class="p">(</span><span class="n">A</span> <span class="o">^</span> <span class="n">A</span><span class="p">,</span> <span class="n">all_models</span><span class="o">=</span><span class="kc">True</span><span class="p">))</span>
<span class="go">UNSAT</span>
</pre></div>
</div>
</dd></dl>

</section>
</section>


            <div class="clearer"></div>
          </div>
        </div>
      </div>
      <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
        <div class="sphinxsidebarwrapper">
            <p class="logo"><a href="../index.html">
              <img class="logo" src="../_static/sympylogo.png" alt="Logo"/>
            </a></p>
  <h3><a href="../index.html">Table of Contents</a></h3>
  <ul>
<li><a class="reference internal" href="#">Logic</a><ul>
<li><a class="reference internal" href="#introduction">Introduction</a></li>
<li><a class="reference internal" href="#forming-logical-expressions">Forming logical expressions</a></li>
<li><a class="reference internal" href="#boolean-functions">Boolean functions</a></li>
<li><a class="reference internal" href="#simplification-and-equivalence-testing">Simplification and equivalence-testing</a></li>
<li><a class="reference internal" href="#module-sympy.logic.inference">Inference</a></li>
</ul>
</li>
</ul>

  <h4>Previous topic</h4>
  <p class="topless"><a href="liealgebras/index.html"
                        title="previous chapter">Lie Algebra</a></p>
  <h4>Next topic</h4>
  <p class="topless"><a href="matrices/index.html"
                        title="next chapter">Matrices</a></p>
  <div role="note" aria-label="source link">
    <h3>This Page</h3>
    <ul class="this-page-menu">
      <li><a href="../_sources/modules/logic.rst.txt"
            rel="nofollow">Show Source</a></li>
    </ul>
   </div>
<div id="searchbox" style="display: none" role="search">
  <h3 id="searchlabel">Quick search</h3>
    <div class="searchformwrapper">
    <form class="search" action="https://docs.sympy.org/latest/search.html" method="get">
      <input type="text" name="q" aria-labelledby="searchlabel" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false"/>
      <input type="submit" value="Go" />
    </form>
    </div>
</div>
<script>$('#searchbox').show(0);</script>
        </div>
      </div>
      <div class="clearer"></div>
    </div>
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../genindex.html" title="General Index"
             >index</a></li>
        <li class="right" >
          <a href="../py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="right" >
          <a href="matrices/index.html" title="Matrices"
             >next</a> |</li>
        <li class="right" >
          <a href="liealgebras/index.html" title="Lie Algebra"
             >previous</a> |</li>
        <li class="nav-item nav-item-0"><a href="../index.html">SymPy 1.9 documentation</a> &#187;</li>
          <li class="nav-item nav-item-1"><a href="index.html" >SymPy Modules Reference</a> &#187;</li>
        <li class="nav-item nav-item-this"><a href="#">Logic</a></li> 
      </ul>
    </div>
    <div class="footer" role="contentinfo">
        &#169; Copyright 2021 SymPy Development Team.
      Last updated on Sep 30, 2021.
      Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 4.1.2.
    </div>
  </body>

<!-- Mirrored from docs.sympy.org/latest/modules/logic.html by HTTrack Website Copier/3.x [XR&CO'2014], Sat, 15 Jan 2022 03:24:30 GMT -->
</html>